#!/bin/bash

# 关闭交换分区
swapoff -a #临时关闭
sed -i 's/.*swap.*/#&/' /etc/fstab #永久关闭交换区

# 禁用selinux
setenforce 0 #临时关闭
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config #永久关闭

# 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

# 添加k8s更新源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

#添加docker镜像源
yum install -y yum-utils device-mapper-persistent-data lvm2 net-tools
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#安装docker
yum -y install docker-ce

#使用docker 加速
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": ["https://jcc6kyje.mirror.aliyuncs.com"],
    "exec-opts":["native.cgroupdriver=systemd"]
}
EOF
systemctl daemon-reload
systemctl restart docker

#安装k8s
# 安装指定版本，使用命令(需要使用 docker)
yum install -y kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0
systemctl enable kubelet
systemctl start kubelet

#查看版本
kubeadm version
kubectl version --client
kubelet --version